<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xsi:schemaLocation='urn:oasis:names:tc:emergency:EDXL:HAVE:1.0 edxl-have_pr3.xsd' xmlns:have='urn:oasis:names:tc:emergency:EDXL:HAVE:1.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xal='urn:oasis:names:tc:ciq:xal:3' xmlns:xnl='urn:oasis:names:tc:ciq:xnl:3' xmlns:xpil='urn:oasis:names:tc:ciq:xpil:3'>
	<xsl:output method="html" indent="yes"/>
	<xsl:template match="//have:HospitalStatus">
		<html>
			<head>
				<title>HAVE Message</title>				
			</head>
			<body>				
				<div id="have-main">
					<xsl:apply-templates/>
				</div>
				<style type="text/css"><![CDATA[
					#have-main { min-width: 350px; }
					
					#have-main .indented { padding-left: 5px; }
					#have-main .red-status { color: red; }
					#have-main .green-status { color: green; }
					
					#have-main .hospital-name { font-weight: bold; padding: 3px 0; text-align: center; background-color: #07c; color: white; }					
					#have-main .section { border: 1px solid black; margin-top: 3px;  }
					#have-main .section-header { font-weight: bold; padding-bottom: 3px; text-align: center; background-color: #4a6b82; color: white; }										
				]]></style>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="have:Hospital">
		<xsl:call-template name="hospital-info">
			<xsl:with-param name="org" select="have:Organization"/>
		</xsl:call-template>
		<xsl:call-template name="bc-status">
			<xsl:with-param name="bcs" select="have:HospitalBedCapacityStatus"/>
		</xsl:call-template>
		<xsl:call-template name="sc-status">
			<xsl:with-param name="scs" select="have:ServiceCoverageStatus"/>
		</xsl:call-template>
		<xsl:call-template name="hf-status">
			<xsl:with-param name="hfs" select="have:HospitalFacilityStatus"/>
		</xsl:call-template>
		<xsl:call-template name="hr-status">
			<xsl:with-param name="hrs" select="have:HospitalResourceStatus"/>
		</xsl:call-template>
		<xsl:call-template name="ed-status">
			<xsl:with-param name="eds" select="have:EmergencyDepartmentStatus"/>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="hospital-info">
		<xsl:param name="org"/>
		<xsl:if test="$org">
			<xsl:call-template name="hospital-name">
				<xsl:with-param name="org-info" select="$org/have:OrganizationInformation"/>
			</xsl:call-template>
			<div class="section">
				<div class="section-header">Hospital Info</div>
				<strong>Address: </strong><xsl:value-of select="$org/have:OrganizationInformation/xpil:Addresses/xpil:Address/xal:FreeTextAddress/xal:AddressLine"/><br/>
				<strong>ZIP: </strong><xsl:value-of select="$org/have:OrganizationInformation/xpil:Addresses/xpil:Address/xal:PostCode/xal:Identifier"/><br/>
				<strong>Administrative Area: </strong><xsl:value-of select="$org/have:OrganizationInformation/xpil:Addresses/xpil:Address/xal:AdministrativeArea/xal:NameElement"/><br/>
				<strong>Sub Administrative Area: </strong><xsl:value-of select="$org/have:OrganizationInformation/xpil:Addresses/xpil:Address/xal:AdministrativeArea/xal:SubAdministrativeArea/xal:NameElement"/>
			</div>
		</xsl:if>
	</xsl:template>
	<xsl:template name="hospital-name">
		<xsl:param name="org-info"/>
		<div class="hospital-name">
			<xsl:value-of select="$org-info/xnl:OrganisationName/xnl:NameElement"/>
		</div>
	</xsl:template>
	<xsl:template name="bc-status">
		<xsl:param name="bcs"/>
		<xsl:if test="$bcs">
			<div class="section">
				<div class="section-header">Bed Capacity Status</div>
				<xsl:for-each select="have:BedCapacity">
					<strong>Bed Type: </strong><xsl:value-of select="have:BedType"/><br/>
					<div class="indented">
						<strong>Available: </strong><xsl:value-of select="have:Capacity/have:AvailableCount"/><br/>
						<strong>Baseline: </strong><xsl:value-of select="have:Capacity/have:BaselineCount"/><br/>
					</div>
				</xsl:for-each>
			</div>
		</xsl:if>
	</xsl:template>
	<xsl:template name="sc-status">
		<xsl:param name="scs"/>
		<xsl:if test="$scs">
		  <div class="section">
			<div class="section-header">Service Coverage Status</div>
			<xsl:if test="$scs/have:Burn">
				<div class="indented">
					<strong>Burn: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Burn"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Cardiology">
				<div class="indented">
					<strong>Cardiology: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Cardiology"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Dialysis">
				<div class="indented">
					<strong>Dialysis: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Dialysis"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:EmergencyDepartment">
				<div class="indented">
					<strong>Emergency Department: </strong>
					<xsl:variable name="EmergencyDepartmentStatus">
						<xsl:value-of select="$scs/have:EmergencyDepartment" />
					</xsl:variable>						
					<xsl:choose>
						<xsl:when test="contains($EmergencyDepartmentStatus, 'true')">
							Diversion
						</xsl:when>
						<xsl:when test="contains($EmergencyDepartmentStatus, 'false')">
							Open
						</xsl:when>
						<xsl:otherwise>
							--
						</xsl:otherwise>
					</xsl:choose>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:HyperbaricChamber">
				<div class="indented">
					<strong>Hyperbaric Chamber: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:HyperbaricChamber"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:InfectiousDisease">
				<div class="indented">
					<strong>Infectious Disease: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:InfectiousDisease"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Neonatology">
				<div class="indented">
					<strong>Neonatology: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Neonatology"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Neurology">
				<div class="indented">
					<strong>Neurology: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Neurology"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:OBGYN">
				<div class="indented">
					<strong>OBGYN: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:OBGYN"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Ophthalmology">
				<div class="indented">
					<strong>Ophthalmology: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Ophthalmology"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Orthopedic">
				<div class="indented">
					<strong>Orthopedic: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Orthopedic"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Pediatrics">
				<div class="indented">
					<strong>Pediatrics: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Pediatrics"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Psychiatric">
				<div class="indented">
					<strong>Psychiatric: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Psychiatric"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:Surgery">
				<div class="indented">
					<strong>Surgery: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:Surgery"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:TransportServices">
				<div class="indented">
					<strong>Transport Services: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:TransportServices"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:TraumaCenterServices">
				<div class="indented">
					<strong>Trauma Center Services: </strong>
					<xsl:call-template name="colored-status">
						<xsl:with-param name="statusString" select="$scs/have:TraumaCenterServices"/>
					</xsl:call-template>
				</div>
			</xsl:if>
			<xsl:if test="$scs/have:AdditionalStatus/have:Service">
				<br/>
				<div class="indented">
					<div>
						<strong>Addtional Status</strong>
					</div>
					<div class="indented">
						<xsl:for-each select="$scs/have:AdditionalStatus/have:Service">
							<xsl:value-of select="have:Name"/> = 
							<xsl:call-template name="colored-status">
								<xsl:with-param name="statusString" select="have:Status"/>
							</xsl:call-template>
							<xsl:if test="position() != last()">
								<br/>
							</xsl:if>
						</xsl:for-each>
					</div>
				</div>
			</xsl:if>		
		  </div>
	  </xsl:if>
	</xsl:template>
	<xsl:template name="hf-status">
		<xsl:param name="hfs"/>
		<xsl:if test="$hfs">
		  <div class="section">
			<div class="section-header">Facility Status</div>
			<xsl:if test="$hfs/have:ClinicalStatus">
				<div class="indented">
					<strong>Clinical Status: </strong><xsl:value-of select="$hfs/have:ClinicalStatus"/>
				</div>
			</xsl:if>
			<xsl:if test="$hfs/have:FacilityStatus">
				<div class="indented">
					<strong>Facility Status: </strong><xsl:value-of select="$hfs/have:FacilityStatus"/>
				</div>
			</xsl:if>
			<xsl:if test="$hfs/have:SecurityStatus">
				<div class="indented">
					<strong>Security Status: </strong><xsl:value-of select="$hfs/have:SecurityStatus"/>
				</div>
			</xsl:if>
			<xsl:if test="$hfs/have:CommentText">
				<div class="indented">
					<div>
						<strong>Comment: </strong>
					</div>
					<div class="indented">
						<xsl:value-of select="$hfs/have:CommentText"/>
					</div>
				</div>
			</xsl:if>
			<xsl:if test="$hfs/have:AdditionalStatus/have:Service">
				<br/>
				<div class="indented">
					<div>
						<strong>Addtional Status</strong>
					</div>
					<div class="indented">
						<xsl:for-each select="$hfs/have:AdditionalStatus/have:Service">
							<xsl:value-of select="have:Name"/> = <xsl:value-of select="have:Status"/>
							<xsl:if test="position() != last()">
								<br/>
							</xsl:if>
						</xsl:for-each>
					</div>
				</div>
			</xsl:if>		
		  </div>
	  </xsl:if>
	</xsl:template>
	<xsl:template name="hr-status">
		<xsl:param name="hrs"/>
		<xsl:if test="$hrs">
		  <div class="section">
			<div class="section-header">Resource Status</div>
			<xsl:if test="$hrs/have:Staffing">
				<div class="indented">
					<strong>Staffing: </strong><xsl:value-of select="$hrs/have:Staffing"/>
				</div>
			</xsl:if>
			<xsl:if test="$hrs/have:FacilityOperations">
				<div class="indented">
					<strong>Facility Operations: </strong><xsl:value-of select="$hrs/have:FacilityOperations"/>
				</div>
			</xsl:if>
			<xsl:if test="$hrs/have:ClinicalOperations">
				<div class="indented">
					<strong>Clinical Operations: </strong><xsl:value-of select="$hrs/have:ClinicalOperations"/>
				</div>
			</xsl:if>
			<xsl:if test="$hrs/have:ResourcesInformationText">
				<xsl:for-each select="$hrs/have:ResourcesInformationText">
					<div class="indented"><xsl:value-of select="." /></div><br/>
				</xsl:for-each>
			</xsl:if>		
		  </div>
	  </xsl:if>
	</xsl:template>
	<xsl:template name="ed-status">
		<xsl:param name="eds"/>
		<xsl:if test="$eds">
			<div class="section">
				<div class="section-header">Emergency Department Status</div>
				<xsl:if test="$eds/have:EMSTraffic/have:EMSTrafficStatus">
					<div class="indented">
						<strong>EMS Traffic: </strong>
						<xsl:value-of select="$eds/have:EMSTraffic/have:EMSTrafficStatus"/>
					</div>
				</xsl:if>
				<xsl:if test="$eds/have:CommentText">
					<div class="indented">
					<div>
						<strong>Comment: </strong>
					</div>
					<div class="indented">
						<xsl:value-of select="$eds/have:CommentText"/>
					</div>
				</div>
				</xsl:if>
				<xsl:if test="$eds/have:AdditionalStatus/have:Service">
					<br/>
					<div class="indented">
						<div>
							<strong>Addtional Status</strong>
						</div>
						<div class="indented">
							<xsl:for-each select="$eds/have:AdditionalStatus/have:Service">
								<xsl:value-of select="have:Name"/> = <xsl:value-of select="have:Status"/>
								<xsl:if test="position() != last()">
									<br/>
								</xsl:if>
							</xsl:for-each>
						</div>
					</div>
				</xsl:if>
			</div>
		</xsl:if>
	</xsl:template>
	<xsl:template name="colored-status">
		<xsl:param name="statusString"/>
		<xsl:choose>
			<xsl:when test="$statusString != ''">
				<xsl:variable name="status" select="$statusString = 'true' or $statusString = 'True' or $statusString = '1'"/>
				<xsl:choose>
					<xsl:when test="$status = true()">
						<span class="green-status"><strong>Available</strong></span>
					</xsl:when>
					<xsl:otherwise><span class="red-status"><strong>Not Available</strong></span></xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>--</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
